why the earth has a magnetic field